// pages/accidentAssi/accidentAssi.js
import config from "../../config.js";
var util = require('../../utils/util.js');
const openIdUrl = config;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //城市列表
    cityList: ["西安", "咸阳", "宝鸡"],
    cityIndex: 0,
    address: "",
    date: "0000-00-00",
    time: "00:00",
    name: "",
    tel: "",
    locLatitude: "",
    locLongitude: ""
  },

  cityChange: function (e) {
    this.setData({
      cityIndex: e.detail.value,
    })
  },

  dateChange: function (e) {
    this.setData({
      date: e.detail.value,
    })
  },

  addressChange: function (e) {
    this.setData({
      address: e.detail.value,
    })
  },

  timeChange: function (e) {
    this.setData({
      time: e.detail.value,
    })
  },
  telChange: function (e) {
    this.setData({
      tel: e.detail.value,
    })
  },

  makeCall: function () {
    wx.makePhoneCall({
      phoneNumber: "88888888",
    })
  },


  submit: function () {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    var user = wx.getStorageSync("user");
    console.log(user);
    var houseKeeperId = user.housekeeper.keeperId;
    console.log(houseKeeperId);
    var orderType = 8;
    console.log(orderType);
    var serviceType = 2;
    console.log(serviceType);
    var carId = 1;
    console.log(carId);
    var comId = 0;
    console.log(comId);
    var orderFrom = 2;
    console.log(orderFrom);
    var addressReturn = that.data.cityList[that.data.cityIndex] + "市" + that.data.address;
    if (that.data.address == "") {
      wx.showToast({
        title: "请输入地址",
        icon: 'none',
        mask: true,
        duration: 2000
      })
      return false;
    }
    console.log(addressReturn);
    var tel = user.tel;
    
    console.log(tel);
    var returnTime = that.data.date + " " + that.data.time;
    console.log(returnTime);


    wx.request({
      url: "https://" + openIdUrl.host + "/App/rescureSubbmit.action",
      data: {
        houseKeeperId: houseKeeperId,
        orderType: orderType,
        serviceType: serviceType,
        carId: carId,
        comId: comId,
        pickTime: returnTime,
        orderFrom: orderFrom,
        address: addressReturn,
        tel: tel,
        name:that.data.name,
        returnTime: returnTime,
        locLatitude: that.data.locLatitude,
        locLongitude: that.data.locLongitude
      },
      success: function (res) {
        console.log(res);
        wx.hideLoading();
        if (res.data.status == 200) {
          console.log(res.data.data.content);
          wx.showModal({
            title: "恭喜您",
            content: "预约成功，车管家将会在10分钟内通过电话与您沟通详情 ，请保持电话畅通！谢谢！",
            showCancel: false,
            confirmColor: "#137AF0",
            success: function () {
              wx.switchTab({
                url: "../order/order",
              })
            }
          })

        } else {
          wx.hideLoading();
          wx.showToast({
            title: res.data.message + "",
            icon: 'none',
            mask: true,
            duration: 2000
          })
        }

      }
    })
    
  },
  nextStep: function () {
    console.log(1);
    this.submit();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var user = wx.getStorageSync("user");
    this.setData({
      name: user.name,
      tel: user.tel
    })
    var date = util.getDate();
    console.log(date);
    this.setData({
      date: date,
    })
    var that = this;
    wx.getLocation({
      success: function (res) {
        console.log(res);
        that.setData({
          locLatitude: res.latitude,
          locLongitude: res.longitude
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})